/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-06-03
 * Time: 12:05
 */
class Solution1 {
    int count, ret;
    public int kthSmallest(TreeNode root, int k) {
        count = k;
        dfs(root);
        return ret;
    }

    void dfs(TreeNode root) {
        if(root == null || count == 0) {
            return;
        }

        dfs(root.left);

        count--;
        if(count == 0) {
            ret = root.val;
        }

        if(count == 0) {
            return;
        }
        dfs(root.right);
    }
}
